<template>
    <div class="data-info" v-loading="loading">
        <div class="condition">
            <div class="item">
                <span>状态：</span>
                <el-select v-model="params.reply" style="width:85px" @on-change="searchBtn">
                    <el-option value="all" label="全部"/>
                    <el-option value="no" label="待回复"/>
                    <el-option value="yes" label="已回复"/>
                </el-select>
            </div>
            <div class="item">
                <span>反馈时间：</span>
                <date-picker @change="dateChange"/>
            </div>
            <div class="item">
                <span>手机号：</span>
                <el-input v-model="params.mobile" style="width: 110px;" :maxlength="11"/>
            </div>
            <el-button type="primary" @click="searchBtn">查询</el-button>
        </div>
        <el-table :data="data">
            <el-table-column prop="mobile" label="手机号码"/>
            <el-table-column prop="nick_name" label="昵称"/>
            <el-table-column prop="content" label="内容"/>
            <el-table-column prop="create_time" label="反馈时间"/>
            <el-table-column label="回复">
                <template slot-scope="{row}">
                    <span class="success" v-if="row.is_reply == 1">是</span>
                    <span class="red" v-else>否</span>
                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="{row}">
                    <a class="blur r5" @click="showDetail(row)">详情</a>
                    <a class="red" @click="del(row.id)">删除</a>
                </template>
            </el-table-column>
        </el-table>
        <page :total="total" :current.sync="params.page" :size.sync="params.size" @change="search"/>
    </div>
</template>

<script>
    import {feedbackInfo, feedbackLists} from "@/api";
    import detail from "./com/detail";
    import DatePicker from "@/components/date/picker";
    import Page from "@/components/page/index";

    export default {
        components: {Page, DatePicker},
        data() {
            return {
                params: {
                    page: 1,
                    size: 10,
                    reply: 'all'
                },
                loading: false,
                data: [],
                total: 0
            }
        },
        created() {
            this.search();
        },
        methods: {
            search() {
                this.loading = true;
                feedbackLists(this.params, (res) => {
                    this.loading = false;
                    this.data = res.lists;
                    this.total = parseInt(res.total);
                })
            },
            pageChange(obj) {
                this.params.page = obj.current;
                this.params.size = obj.size;
                this.search();
            },
            // 搜索
            searchBtn() {
                this.params.page = 1;
                this.search();
            },
            dateChange(date) {
                if (date[0]) {
                    this.params.time = date[0] + ',' + date[1];
                } else {
                    this.params.time = '';
                }
                this.searchBtn();
            },
            del(id) {
                this.$confirm("确定删除该反馈信息？", () => {
                    feedbackInfo('delete', {id: id}, () => {
                        this.search();
                        this.$Modal.remove();
                    })
                })
            },
            showDetail(obj) {
                this.$drawer({
                    title: '反馈详情',
                    component: detail,
                    data: obj,
                    close: this.search()
                })
            }
        }
    }
</script>
